﻿using TableTool.Model;

namespace TableTool
{
    public partial class ucUserData : UserControl
    {
        /// <summary>
        /// 数据
        /// </summary>
        public LookModel userDataItem { get; set; }
        /// <summary>
        /// 监控窗体
        /// </summary>
        AlarmFrm alarmFrms { get; set; }
        /// <summary>
        /// 显示标识
        /// </summary>
        bool showFlag { get; set; } = false;
        public ucUserData()
        {
            InitializeComponent();
            this.Load += UcUserData_Load;
        }

        private void UcUserData_Load(object? sender, EventArgs e)
        {
            label1.Text = userDataItem.groupName + "-" + userDataItem.Name;
            textBox1.Text = userDataItem.width + "," + userDataItem.height;
        }

        public void Close()
        {
            if (alarmFrms != null)
            {
                alarmFrms.Close();
            }
        }

        /// <summary>
        /// 执行
        /// </summary>
        public void Ex()
        {
            if (alarmFrms != null)
            {
                alarmFrms.Ex();
            }

        }

        public bool To0(string downkeys)
        {
            if (alarmFrms != null)
            {
                return alarmFrms.ClickEx(downkeys);
            }
            return false;
        }

        private void checkBox1_Click(object sender, EventArgs e)
        {
            if (alarmFrms == null)
            {
                alarmFrms = new AlarmFrm();
                alarmFrms.lookModel = userDataItem;
                alarmFrms.TopMost = true;
            }
            if (checkBox1.Checked)
            {
                int w = 209, h = 30;
                var wh = textBox1.Text.Split(',');
                if (wh.Length == 2)
                {
                    var dst1 = int.TryParse(wh[0], out w);
                    var dst2 = int.TryParse(wh[1], out h);
                    if (dst1 && dst2)
                    {
                        if (w == 0 || h == 0)
                        {
                            w = 209; h = 30;
                        }
                    }
                    else
                    {

                    }
                }
                userDataItem.width = w;
                userDataItem.height = h;
                textBox1.Text = w + "," + h;
                alarmFrms.Show();
            }
            else { alarmFrms.Close(); alarmFrms = null; }
        }



        private void button1_Click(object sender, EventArgs e)
        {
            userDataItem.locationX = 0;
            userDataItem.locationY = 0;
        }
    }
}
